*******************************************************************************
***
*** STATA syntax to merge the individual-level file (MASTER) with separate 
*** country/survey files (PLUGs).
***
*******************************************************************************

***
*** set working directory containing MASTER, PLUG_COUNTRY and PLUG_SURVEY files
*** e.g. cd "C:\"
***

cd "/home/sdr/master/merge/"

***
*** open MASTER file
***

use "MASTER.dta"

***
*** merge MASTER and PLUG_COUNTRY files
***

generate T_COUNTRY = T_COUNTRY_L2U
merge m:1 T_COUNTRY using "PLUG_COUNTRY.dta"
drop if _merge == 2
drop _merge T_COUNTRY

***
*** merge MASTER and PLUG_SURVEY files
***

merge m:1 T_PROJECT_NAME T_PROJECT_WAVE T_COUNTRY_L1U T_COUNTRY_L2U using "PLUG_SURVEY.dta"
drop if _merge == 2
drop _merge

***
*** save the resulting file; you may want to compress the file before saving, to 
*** reduce the size on disk
***

* compress

* save "MASTER-merged.dta"

* exit
